#include "volumereader.hpp"

VolumeReader::VolumeReader() {
  init();
}

VolumeReader::VolumeReader(const QString &fileName) {
  init();
  read(fileName);
}

VolumeReader::~VolumeReader() {
  delete handler;
  delete xmlReader;
}

void VolumeReader::init() {
  xmlReader=new QXmlSimpleReader();
  handler=new VolumeContentHandler();
  xmlReader->setContentHandler(handler);
  xmlReader->setErrorHandler(handler);
}

void VolumeReader::read(const QString &fileName) {
  QFile file(fileName);
  QXmlInputSource *source=new QXmlInputSource(&file);
  xmlReader->parse(source);
  delete source;
}

const Vector3i & VolumeReader::getSize() const {
  return handler->getSize();
}

double VolumeReader::getDelta() {
  return handler->getDelta();
}

const Vector3d & VolumeReader::getPosition() const {
  return handler->getPosition();
}

unsigned char * VolumeReader::getVoxels() {
  return handler->getVoxels();
}

int VolumeReader::getNumVoxels() {
  return handler->getNumVoxels();
}
